var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/table/child/body.tsx
var body_exports = {};
__export(body_exports, {
  TableBody: () => TableBody
});
module.exports = __toCommonJS(body_exports);
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_tooltip = require("../../antd/tooltip");
var import_common = require("../base/common");
var import_base = __toESM(require("../base/index"));
var import_factory = require("../editor/factory");
var import_useAutoScroll = require("../hook/useAutoScroll");
var import_useKeyDown = require("../hook/useKeyDown");
var import_util = require("../util");
var aggregateTitle = {
  min: "最小值：",
  max: "最大值：",
  avg: "平均值：",
  sum: "合计：",
  count: "记录数："
};
var CopyIcon = ({ text }) => {
  const [copy, setCopy] = (0, import_react.useState)(null);
  const copyText = (e) => {
    e.stopPropagation();
    import_util.util.copyText(text);
    setCopy(
      setTimeout(() => {
        setCopy(null);
      }, 3e3)
    );
  };
  (0, import_react.useEffect)(() => {
    return () => copy && clearTimeout(copy);
  }, []);
  return /* @__PURE__ */ import_react.default.createElement("a", null, copy ? /* @__PURE__ */ import_react.default.createElement(import_icons.CheckOutlined, { className: "cell-content-copy", style: { color: "#52c41a" } }) : /* @__PURE__ */ import_react.default.createElement(import_icons.CopyOutlined, { className: "cell-content-copy", onClick: copyText }));
};
var ContentCell = ({ row, rowIndex, column, disabled, editing }) => {
  var _a, _b;
  const {
    table,
    table: {
      props: { rowHeight },
      state: {
        params: { pageIndex, pageSize }
      }
    }
  } = (0, import_react.useContext)(import_common.TableContext);
  const { dataIndex: dIndex, dataIndexField, tooltip, copyable, editor, render } = column;
  const { overflow = void 0, type: tooltipType } = import_util.util.isObject(tooltip) ? tooltip : { type: tooltip };
  const tooltipOverflow = overflow ?? !import_util.util.isFunction(tooltipType);
  const dataIndex = dataIndexField || dIndex;
  const params = {
    table,
    row,
    value: import_util.util.getObjValue(row, dataIndex),
    dataIndex,
    rowIndex,
    pageIndex,
    pageSize,
    disabled,
    onChange(val) {
      table.updateRowDataByIndex(rowIndex, { [dataIndex]: val }, true);
    }
  };
  const displayField = (0, import_util.getDisplayField)({ row, editor, dataIndex });
  const contentInfo = (0, import_react.useMemo)(() => {
    if (render) {
      return render(params);
    } else {
      return /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: "nowrap",
          style: { whiteSpace: `${rowHeight === "auto" ? "pre-wrap" : "nowrap"}`, wordBreak: "break-all" }
        },
        (0, import_util.displayText)(import_util.util.getObjValue(row, displayField, import_util.util.getObjValue(row, dataIndex, "")))
      );
    }
  }, [row, row.__update__, (_a = row.children) == null ? void 0 : _a.length, params.value, rowHeight, disabled, dataIndex, displayField]);
  const tooltipFn = (0, import_util.useReturnCallback)(() => {
    return import_util.util.isFunction(tooltipType) ? tooltipType(params) : tooltipType === "render" ? contentInfo : (0, import_util.displayText)(import_util.util.getObjValue(row, displayField));
  }, [contentInfo, displayField]);
  const keyValue = row[table.getKeyField()];
  const errorInfo = editing || disabled ? "" : (_b = table.state.errors[`${keyValue}:${column.dataIndex}`]) == null ? void 0 : _b.info.map(([, error]) => error).join(";");
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, !tooltipType ? contentInfo : /* @__PURE__ */ import_react.default.createElement(import_tooltip.Tooltip, { title: tooltipFn, overflow: tooltipOverflow }, /* @__PURE__ */ import_react.default.createElement("span", { className: "nowrap" }, contentInfo)), copyable && params.value && /* @__PURE__ */ import_react.default.createElement(CopyIcon, { text: params.value }), errorInfo && /* @__PURE__ */ import_react.default.createElement(import_tooltip.Tooltip, { title: errorInfo, color: "#f50" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "cell-error" })));
};
var EditorCell = (props) => {
  const { table } = (0, import_react.useContext)(import_common.TableContext);
  const { row, column, rowIndex, editing, active, disabled } = props;
  const { activeCellEditor, editCellHighlight } = table.props;
  const startEditing = () => {
    if (table._movement > 5) {
      table._movement = 0;
      return;
    }
    if (table.isDisabled({ row, dataIndex: column.dataIndex, column })) {
      return;
    }
    table.setEditLock(true);
    setTimeout(() => {
      table.setEditLock(false);
    }, 16);
    table.startEditing({ rowIndex, dataIndex: column.dataIndex });
  };
  const tmpProps = {
    [`${activeCellEditor === "doubleClick" ? "onDoubleClick" : "onClick"}`]: startEditing
  };
  const inputBg = editCellHighlight && !disabled ? { backgroundColor: `${import_util.util.isString(editCellHighlight) ? editCellHighlight : "rgba(255,235,205,.6)"}` } : {};
  if (activeCellEditor !== "doubleClick") {
    tmpProps.onMouseDown = (e) => {
      table._movement = e.screenX;
    };
    tmpProps.onMouseUp = (e) => {
      table._movement = Math.abs(e.screenX - table._movement || 0);
    };
  }
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: import_util.util.classNames(
        "editor-container",
        `${editing ? "cell-editing" : active ? "cell-active" : ""}`,
        `${disabled ? "cell-disabled" : "input"}`
      ),
      style: {
        ...table.cellStyle,
        ...editing && !disabled ? { padding: 1 } : {},
        ...(0, import_util.convertStyle)(column.cellStyle),
        tabIndex: 1,
        ...inputBg
      },
      ...tmpProps
    },
    /* @__PURE__ */ import_react.default.createElement(import_factory.EditorFactory, { column, row, table, editing }, /* @__PURE__ */ import_react.default.createElement(ContentCell, { ...props }))
  );
};
var RenderCell = import_react.default.memo(
  (props) => {
    const { column, table, row } = props;
    const disabled = table.isDisabled({ row, dataIndex: column.dataIndex, column });
    return column.editor ? /* @__PURE__ */ import_react.default.createElement(EditorCell, { ...props, disabled }) : /* @__PURE__ */ import_react.default.createElement(ContentCell, { ...props, disabled });
  },
  (prevProps, nextProps) => {
    const { row: prevRow, table: prevTable, ...prevRest } = prevProps;
    const { row: nextRow, table, ...nextRest } = nextProps;
    const checkedIndex = table.getCheckBoxDataIndex();
    if (nextRow.__update__ || table.updateFlag === import_common.UpdateFlagEnum.ForceUpdate) {
      return false;
    }
    if (table.updateFlag === import_common.UpdateFlagEnum.ColumnChecked) {
      if (nextRest.column.dataIndex === checkedIndex) {
        return false;
      }
      const { [checkedIndex]: c1, ...p } = prevRow;
      const { [checkedIndex]: c2, ...n } = nextRow;
      return (0, import_common.areEqual)(p, n) && (0, import_common.areEqual)(prevRest, nextRest);
    }
    return prevRow === nextRow && (0, import_common.areEqual)(prevRest, nextRest);
  }
);
var FixedBodyCell = (props) => {
  const {
    table,
    columns: { fixedColumns }
  } = (0, import_react.useContext)(import_common.TableContext);
  const {
    rowIndex,
    fixedRight,
    style: { left, right, marginLeft, ...others },
    editing,
    active,
    data: row
  } = props;
  const [editingIndex, editingDataIndex] = editing.split(":");
  const [activeIndex, activeDataIndex] = active.split(":");
  const [editingRowIndex, activeRowIndex] = [parseInt(editingIndex), parseInt(activeIndex)];
  const render = (fixed) => {
    const fixedCols = fixedColumns[fixed].columns;
    if (fixedCols.length === 0 || fixed === "right" && row[import_common.IS_GROUP]) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `fc fixed-cell-${fixed}`,
        style: {
          ...others,
          width: "auto",
          position: "sticky",
          left: fixed === "left" ? 0 : fixedRight,
          zIndex: `${rowIndex + (fixed === "left" ? 2 : 3)}`
        }
      },
      fixedCols.map((column, index) => {
        return row[import_common.IS_GROUP] && index > 0 ? null : /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            key: index,
            "data-key": column.dataIndex,
            className: "virtual-table-cell",
            style: {
              ...table.cellStyle,
              width: column.width,
              position: "relative",
              minHeight: "100%",
              ...(0, import_util.convertStyle)(column.cellStyle)
            }
          },
          /* @__PURE__ */ import_react.default.createElement(
            RenderCell,
            {
              table,
              rowIndex,
              row,
              column,
              active: activeRowIndex === rowIndex && activeDataIndex === column.dataIndex,
              editing: editingRowIndex === rowIndex && editingDataIndex === column.dataIndex
            }
          )
        );
      })
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, render("left"), render("right"));
};
var BodyCell = (props) => {
  const {
    table,
    columns: { fixedColumns, normalColumns: columns }
  } = (0, import_react.useContext)(import_common.TableContext);
  const { columnIndex, rowIndex, style, className, editing, active, data } = props;
  const { cellStyle, dataIndex } = columns[columnIndex];
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      "data-key": dataIndex,
      className: import_util.util.classNames("virtual-table-cell", className),
      style: {
        ...table.cellStyle,
        ...style,
        left: style.left + fixedColumns.left.width,
        ...(0, import_util.convertStyle)(cellStyle)
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      RenderCell,
      {
        table,
        rowIndex,
        row: data,
        column: columns[columnIndex],
        editing,
        active
      }
    )
  );
};
var RowDetail = import_react.default.memo(({ rowIndex, data }) => {
  const {
    table,
    table: {
      props: {
        expandRow: { render: Cmp }
      }
    }
  } = (0, import_react.useContext)(import_common.TableContext);
  return /* @__PURE__ */ import_react.default.createElement(Cmp, { table, row: data, rowIndex });
}, import_common.areEqual);
var ExpandRowCell = (props) => {
  const { rowIndex, data, contentWidth } = props;
  return /* @__PURE__ */ import_react.default.createElement("div", { style: { width: contentWidth } }, /* @__PURE__ */ import_react.default.createElement(RowDetail, { key: rowIndex, rowIndex, data, style: { width: "100%" } }));
};
var AggregateContent = ({ table, column, dataSource, style, inGroup }) => {
  const { aggregates, dataIndex, encrypted } = column;
  const [aggregateResult, setAggregateResult] = (0, import_util.useRefState)({});
  const calc = (0, import_util.useRefCallback)(async () => {
    var _a;
    if (aggregates) {
      const aggregateData = ((_a = table.state.aggregates) == null ? void 0 : _a[dataIndex]) || {};
      const summaryData = table.state.summaryData || {};
      const stateAggregates = summaryData.hasOwnProperty(dataIndex) ? { ...aggregateData, totalSummary: summaryData[dataIndex] } : aggregateData;
      const dataArr = aggregates.some((a) => !stateAggregates.hasOwnProperty(a.type || a)) ? dataSource.map((d) => d[dataIndex]) : [];
      const tmpObj = {};
      for (let i = 0, len = aggregates.length; i < len; i++) {
        const ag = aggregates[i];
        const type = ag.type || ag;
        if (encrypted) {
          tmpObj[i] = "******";
        } else if (stateAggregates.hasOwnProperty(type)) {
          tmpObj[i] = stateAggregates[type];
        } else if (import_util.util.isFunction(ag.calc)) {
          tmpObj[i] = await ag.calc(dataArr, dataSource, dataIndex, inGroup);
        } else {
          tmpObj[i] = import_util.util.getAggregate(type, dataArr);
        }
        if (import_util.util.isFunction(ag.formatter) && tmpObj.hasOwnProperty(i)) {
          tmpObj[i] = ag.formatter(tmpObj[i], { type, dataIndex, data: dataSource, inGroup });
        }
      }
      setAggregateResult(tmpObj);
    }
  });
  (0, import_react.useEffect)(() => {
    const it = setTimeout(calc);
    return () => clearTimeout(it);
  }, [dataIndex, dataSource, aggregates]);
  const getTitle = (ag) => {
    return aggregateTitle[ag] || (import_util.util.isFunction(ag.title) ? ag.title(inGroup) : ag.title);
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "virtual-table-cell", style }, /* @__PURE__ */ import_react.default.createElement("div", { style: { maxHeight: "100%", width: "100%" } }, aggregates == null ? void 0 : aggregates.map((ag, idx) => /* @__PURE__ */ import_react.default.createElement("div", { key: idx, className: "nowrap", style: { lineHeight: 1.5, ...ag.style } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { fontWeight: `${inGroup ? "normal" : 600}` } }, getTitle(ag)), /* @__PURE__ */ import_react.default.createElement("span", { style: { fontWeight: 600 } }, aggregateResult[idx] ?? /* @__PURE__ */ import_react.default.createElement(import_icons.LoadingOutlined, null))))));
};
var AggregateCell = (props) => {
  const {
    table,
    columns: { fixedColumns, normalColumns: columns }
  } = (0, import_react.useContext)(import_common.TableContext);
  const {
    columnIndex,
    fixedRight,
    style,
    style: { height, left, right, marginLeft, ...others },
    subDataSource
  } = props;
  const dataSource = subDataSource || table.getAggregateData();
  const inGroup = !!subDataSource;
  if (columnIndex === -1) {
    const getColumnStyle = (column) => ({
      minHeight: (0, import_util.getGlobalConfig)().default.tableConfig.rowHeight,
      ...table.cellStyle,
      ...(0, import_util.convertStyle)(column.cellStyle),
      ...table.props.aggregateStyle,
      position: "relative",
      width: column.width
    });
    const render = (fixed) => {
      const fixedCols = fixedColumns[fixed].columns;
      if (fixedCols.length === 0) {
        return null;
      }
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `fc fixed-cell-${fixed}`,
          style: {
            ...others,
            width: "auto",
            position: "sticky",
            left: fixed === "left" ? 0 : fixedRight,
            zIndex: fixed === "left" ? 2 : 3
          }
        },
        fixedCols.map((column, index) => /* @__PURE__ */ import_react.default.createElement(
          AggregateContent,
          {
            key: index,
            table,
            column,
            inGroup,
            dataSource,
            style: getColumnStyle(column)
          }
        ))
      );
    };
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, render("left"), render("right"));
  } else {
    const column = columns[columnIndex];
    return /* @__PURE__ */ import_react.default.createElement(
      AggregateContent,
      {
        inGroup,
        table,
        column,
        dataSource,
        style: {
          minHeight: (0, import_util.getGlobalConfig)().default.tableConfig.rowHeight,
          ...table.cellStyle,
          ...style,
          height: "100%",
          left: style.left + fixedColumns.left.width,
          ...(0, import_util.convertStyle)(column.cellStyle),
          ...table.props.aggregateStyle
        }
      }
    );
  }
};
var GroupRowCell = (props) => {
  var _a;
  const { table } = (0, import_react.useContext)(import_common.TableContext);
  const { rowIndex, style, data: row } = props;
  const {
    title,
    header,
    dataIndex,
    dataIndexField,
    render = ({ row: row2, dataIndex: dataIndex2 }) => `${import_util.util.getObjValue(row2, dataIndex2)}(${row2.children.length})`
  } = row.column;
  const expandIconWidth = ((_a = table.props.expandWidth) == null ? void 0 : _a.width) || 24;
  const di = dataIndexField || dataIndex;
  const tip = import_util.util.isFunction(header) ? header({ title, dataIndex, column: row.column, inGroup: true }) : /* @__PURE__ */ import_react.default.createElement("span", { style: { fontWeight: 600 } }, `${header || title}:`);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "virtual-table-cell", style: { ...table.cellStyle, ...style, left: style.left + expandIconWidth } }, tip, /* @__PURE__ */ import_react.default.createElement("span", { style: { margin: `${tip ? "0 4px" : 0}` } }, render({
    table,
    row,
    dataIndex: di,
    rowIndex,
    value: import_util.util.getObjValue(row, di),
    inGroup: true
  })));
};
var Cell = import_react.default.memo(
  (props) => {
    switch (props.cellType) {
      case import_common.CellTypeEnum.BodyCell:
        return /* @__PURE__ */ import_react.default.createElement(BodyCell, { ...props });
      case import_common.CellTypeEnum.MergeCell:
        return /* @__PURE__ */ import_react.default.createElement(BodyCell, { ...props, className: "merge-cell" });
      case import_common.CellTypeEnum.FixedBodyCell:
        return /* @__PURE__ */ import_react.default.createElement(FixedBodyCell, { ...props });
      case import_common.CellTypeEnum.ExpandRowCell:
        return /* @__PURE__ */ import_react.default.createElement(ExpandRowCell, { ...props });
      case import_common.CellTypeEnum.AggregateCell:
        return /* @__PURE__ */ import_react.default.createElement(AggregateCell, { ...props });
      case import_common.CellTypeEnum.GroupRowCell:
        return /* @__PURE__ */ import_react.default.createElement(GroupRowCell, { ...props });
      default:
        return null;
    }
  },
  (prevProps, nextProps) => {
    var _a;
    if (nextProps.data.__update__ || ((_a = nextProps.table) == null ? void 0 : _a.updateFlag) === import_common.UpdateFlagEnum.ForceUpdate) {
      return false;
    }
    return (0, import_common.areEqual)(prevProps, nextProps);
  }
);
function TableBody() {
  var _a;
  const {
    table,
    columns: {
      fixedColumns,
      normalColumns,
      editableColumnIndex = [],
      aggregates,
      useFlex,
      allColumns,
      totalColumnWidth,
      avgColumnWidth = 50
    }
  } = (0, import_react.useContext)(import_common.TableContext);
  const headerHeight = table.headerHeight;
  const {
    hiddenHeader,
    rowHeight = 32,
    compact,
    rowDrag,
    isTree = false,
    pagination = false,
    virtualScrolling = true,
    optimize = {},
    expandRow
  } = table.props;
  const [paginationHeight, setPaginationHeight] = (0, import_react.useState)(
    pagination && !pagination.targetContainer ? pagination.height || 48 : 0
  );
  const { width, height, dataSource = [] } = table.state;
  const calcHeaderHeight = hiddenHeader || headerHeight <= 0 ? 0 : headerHeight;
  const tmpRef = (0, import_react.useRef)();
  const itemData = (0, import_react.useMemo)(() => {
    table._renderDataSource = import_util.util.isFunction(table._rowFilter) ? dataSource.filter(table._rowFilter) : dataSource;
    return {
      gridData: {
        table,
        columns: normalColumns,
        fixedColumns,
        aggregates,
        dataSource: table._renderDataSource || [],
        totalColumnWidth,
        scrollbar: { vertical: table.state.vertical }
      }
    };
  }, [normalColumns, fixedColumns, dataSource, aggregates, totalColumnWidth, table._rowFilter]);
  const rowCount = Math.max(1, itemData.gridData.dataSource.length);
  const editable = editableColumnIndex.length > 0 && itemData.gridData.dataSource.length > 0;
  const scrollThrottle = (0, import_util.useThrottle)((scrollParams) => table.notify({ ...scrollParams, table }, "onScroll"), {
    trailing: true,
    leading: false
  });
  const onScroll = (params) => {
    const { scrollLeft } = params;
    const headerDom = table.headerRef.current;
    if (headerDom && headerDom.lastScrollLeft !== scrollLeft) {
      headerDom.lastScrollLeft = scrollLeft;
      headerDom.querySelector(".normal-cells").style.transform = `translateX(-${scrollLeft}px)`;
    }
    scrollThrottle(params);
  };
  (0, import_react.useEffect)(() => {
    return table.subscribe(({ height: height2 }) => {
      setPaginationHeight(height2);
    }, "hideOnSinglePage");
  }, []);
  (0, import_react.useEffect)(() => {
    var _a2;
    const { scrollbar } = itemData.gridData;
    const scrollbarPlaceHolder = (_a2 = table.headerRef.current) == null ? void 0 : _a2.querySelector(".scrollbar-placeholder");
    if (scrollbarPlaceHolder && scrollbar) {
      scrollbarPlaceHolder.style.display = scrollbar.vertical ? "inline-block" : "none";
      table.outRef.current._outerRef.style.overflowY = scrollbar.vertical ? "scroll" : "auto";
    }
  }, [itemData.gridData.dataSource.length, width, height, allColumns]);
  (0, import_useAutoScroll.useAutoScroll)({ table, scrollbar: itemData.gridData.scrollbar });
  (0, import_react.useLayoutEffect)(() => {
    var _a2, _b;
    const vertical = (_b = (_a2 = itemData.gridData) == null ? void 0 : _a2.scrollbar) == null ? void 0 : _b.vertical;
    if (table.state.vertical !== vertical) {
      if (itemData.gridData.dataSource.length > 0 && optimize.vertical || !optimize.vertical) {
        table.refreshView({ state: { vertical }, rowColumnIndex: { columnIndex: 0 } });
      }
    }
  }, [itemData.gridData.dataSource.length, height, width]);
  (0, import_util.useUpdateEffect)(() => {
    var _a2;
    (_a2 = table.outRef.current) == null ? void 0 : _a2.resetAfterColumnIndex(0, true);
  }, [width]);
  (0, import_react.useLayoutEffect)(() => {
    if (rowHeight === "auto") {
      if (!table.props.estimateRowHeight) {
        tmpRef.current = true;
      } else {
        const cellPadding = table._getCellPadding();
        const { fontSize = "var(--font-size-base, 14px)", lineHeight = 1.5714285714285714 } = table.props.estimateRowHeight;
        tmpRef.current = document.createElement("div");
        tmpRef.current.style.cssText = `white-space:pre-wrap;word-break:break-all;position:absolute;padding: ${cellPadding}px; font-size:${fontSize};top:-999px;z-index:-1;visibility: hidden;line-height:${lineHeight};`;
        document.body.appendChild(tmpRef.current);
      }
    }
    return () => {
      if (tmpRef.current && tmpRef.current !== true) {
        document.body.removeChild(tmpRef.current);
      }
      tmpRef.current = void 0;
    };
  }, [rowHeight]);
  (0, import_util.useUpdateEffect)(() => {
    table.refreshView({ rowColumnIndex: { rowIndex: 0 } });
  }, [rowHeight]);
  (0, import_util.useUpdateEffect)(() => {
    var _a2;
    rowHeight === "auto" && ((_a2 = table.outRef.current) == null ? void 0 : _a2.resetAfterRowIndex(0, false));
  }, [itemData.gridData.dataSource]);
  const defaultHeight = compact ? 28 : (0, import_util.getGlobalConfig)().default.tableConfig.rowHeight;
  const tableRowHeight = (rowIndex) => {
    var _a2;
    if (!((_a2 = itemData.gridData.dataSource) == null ? void 0 : _a2.length)) {
      return defaultHeight;
    }
    const padding = table._getCellPadding();
    switch (itemData.gridData.dataSource[rowIndex].cellType) {
      case import_common.CellTypeEnum.AggregateCell:
        return Math.max(defaultHeight, aggregates.length * 21 + padding);
      case import_common.CellTypeEnum.ExpandRowCell:
        const tmp = itemData.gridData.dataSource[rowIndex];
        return Math.max(
          0,
          import_util.util.isFunction(expandRow.height) ? expandRow.height({
            row: tmp.parent,
            rowIndex: tmp.groupIndex
          }) : expandRow.height
        );
      default: {
        if (tmpRef.current) {
          const row = itemData.gridData.dataSource[rowIndex];
          const obj = { height: defaultHeight, width: 0, maxContent: "", len: 0 };
          allColumns.forEach(({ dataIndex }) => {
            const { dataIndexField, width: width2, editor, hidden } = table.getDataIndexMap()[dataIndex];
            if (hidden || width2 <= 0) {
              return;
            }
            const displayField = (0, import_util.getDisplayField)({ editor, row, dataIndex: dataIndexField || dataIndex });
            const value = import_util.util.getObjValue(row, displayField, import_util.util.getObjValue(row, dataIndexField || dataIndex, "")) + "";
            const enLen = value ? value.split("\n").length - 1 : 0;
            const strLen = import_util.util.strLen(value, 2);
            const cw = width2 - padding * 2;
            const esCalcHeight = Math.max(Math.ceil((strLen - enLen) * 6.5 / cw + enLen) * 22 + 2, obj.height);
            if (esCalcHeight > obj.height || esCalcHeight === obj.height && strLen > obj.len) {
              obj.maxContent = value;
              obj.width = cw;
              obj.len = strLen;
              obj.height = esCalcHeight;
            }
          });
          if (obj.maxContent && tmpRef.current !== true) {
            tmpRef.current.style.width = `${obj.width}px`;
            tmpRef.current.innerText = obj.maxContent;
            obj.height = tmpRef.current.offsetHeight;
          }
          return obj.height;
        }
        break;
      }
    }
    return (import_util.util.isFunction(rowHeight) ? rowHeight(rowIndex) : Number(rowHeight)) || defaultHeight;
  };
  const onKeyDown = (0, import_useKeyDown.useKeyDown)(table.bodyRef, [
    table,
    editableColumnIndex,
    itemData.gridData.dataSource.length - 1,
    editable
  ]);
  const draggable = !!rowDrag && !table.groupByColumn;
  const { SortContainer } = (0, import_util.useDraggableSort)(draggable);
  const sortProps = draggable ? {
    ...rowDrag.listeners,
    helperClass: "row-dragging",
    axis: "y",
    lockAxis: "xy",
    pressDelay: rowDrag.pressDelay ?? 250,
    shouldCancelStart: (e) => {
      var _a2;
      const node = import_util.util.closest(e.target, (el2) => el2.sortableInfo);
      if (node && node.sortableInfo) {
        const listeners = rowDrag.listeners || {};
        if (rowDrag.handleIndex && !import_util.util.closest(e.target, (el2) => el2.dataset.key === rowDrag.handleIndex)) {
          return true;
        }
        return !!((_a2 = listeners.shouldCancelStart) == null ? void 0 : _a2.call(listeners, e, node.sortableInfo.index));
      }
      return true;
    },
    onSortEnd: (sortInfo, e) => {
      var _a2;
      const { oldIndex, newIndex } = sortInfo;
      if (oldIndex !== newIndex) {
        const listeners = rowDrag.listeners || {};
        if (((_a2 = listeners.onSortEnd) == null ? void 0 : _a2.call(listeners, sortInfo, e)) === false) {
          return;
        }
        if (isTree) {
          table.moveTreeNode(oldIndex, newIndex);
        } else {
          table.moveRow(oldIndex, newIndex);
        }
      }
    }
  } : null;
  const keyProps = onKeyDown ? {
    tabIndex: 1,
    onKeyDown
  } : null;
  const otherHeight = calcHeaderHeight + paginationHeight;
  const baseHeight = height - otherHeight;
  const estimatedRowHeight = tableRowHeight(0);
  const minHeight = Math.max(0, parseFloat(((_a = table.props.style) == null ? void 0 : _a.minHeight) || 0) - otherHeight);
  const el = /* @__PURE__ */ import_react.default.createElement("div", { ref: table.bodyRef, ...keyProps }, /* @__PURE__ */ import_react.default.createElement(SortContainer, { ...sortProps }, /* @__PURE__ */ import_react.default.createElement(
    import_base.default,
    {
      ref: table.outRef,
      estimatedRowHeight,
      estimatedColumnWidth: avgColumnWidth,
      itemData: itemData.gridData,
      className: `${editable ? "editable" : ""} row-hover rows-container`,
      style: { overflow: `${useFlex ? "hidden" : "auto"} auto`, zIndex: 1 },
      columnCount: itemData.gridData.columns.length,
      columnWidth: (index) => {
        var _a2;
        return (_a2 = itemData.gridData.columns[index]) == null ? void 0 : _a2.width;
      },
      minHeight,
      height: baseHeight > 0 ? baseHeight : rowCount * estimatedRowHeight,
      rowCount,
      virtualScrolling,
      overscanRowCount: virtualScrolling ? 1 : rowCount,
      overscanColumnCount: virtualScrolling ? 10 : itemData.gridData.columns.length,
      useIsScrolling: rowCount > 35,
      onScroll,
      rowHeight: tableRowHeight,
      width
    },
    Cell
  )));
  return table.props.bodyContextMenu || table.props.rowContextMenu ? /* @__PURE__ */ import_react.default.createElement(TableBodyCtx, { table, children: el, ds: itemData.gridData.dataSource }) : el;
}
function TableBodyCtx({ children, table, ds }) {
  const { rowContextMenu, bodyContextMenu } = table.props;
  const [visible, setVisible] = (0, import_react.useState)(false);
  const onVisibleChange = (0, import_util.useRefCallback)((open) => {
    setVisible(open);
  });
  const hidden = (0, import_util.useRefCallback)(() => {
    setVisible(false);
  });
  const dropdownRender = (0, import_util.useRefCallback)(() => {
    const { rowIndex, dataIndex } = (0, import_util.getCellInfoByEvent)();
    let cloneEl;
    if (rowIndex > -1 && rowContextMenu) {
      cloneEl = rowContextMenu(ds[rowIndex], { rowIndex, table, hidden, dataIndex });
    } else if (bodyContextMenu) {
      cloneEl = bodyContextMenu({ table, hidden, rowIndex, dataIndex });
    } else {
      return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
    }
    const cloneElClick = cloneEl.props.onClick;
    return import_react.default.cloneElement(cloneEl, {
      onClick(...args) {
        cloneElClick == null ? void 0 : cloneElClick(...args);
        hidden();
      }
    });
  });
  (0, import_react.useEffect)(() => {
    if (visible) {
      document.body.addEventListener("contextmenu", hidden, true);
      return () => {
        document.body.removeEventListener("contextmenu", hidden, true);
      };
    }
  }, [visible]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Dropdown,
    {
      destroyPopupOnHide: true,
      open: visible,
      onOpenChange: onVisibleChange,
      trigger: ["contextMenu"],
      children,
      dropdownRender
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  TableBody
});
